package com.shenfa.action;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import com.shenfa.bean.Epiboly;
import com.shenfa.bean.PaperCityCrd;
import com.shenfa.service.EpibolyService;

import com.shenfa.util.ResultObject;

/**
 * 外包商信息管理Action
 * 
 * @author yanglong
 *
 */
@SuppressWarnings("serial")
public class EpibolyAction extends BaseAction {

	@Autowired
	private EpibolyService epibolyService;
	
	private static Logger log=Logger.getLogger(EpibolyAction.class);
	private Epiboly epiboly;
	private int start;

	private int limit;
	
	private PaperCityCrd paperCC;

	/**
	 * 根据对象条件查询外包商列表
	 * @return	外包商列表
	 */
	@SuppressWarnings("unchecked")
	public String list() {
		log.debug("epiboly="+epiboly+",start="+start+",limit="+limit);
		List<Epiboly> list = epibolyService.getList(epiboly,start,limit);
		result = ResultObject.build("0", list);
		result.put("total", epibolyService.queryCount(epiboly));
		return SUCCESS;		
	}
	
	/**
	 * 查询卡产品关联的外包商
	 * @return
	 */
	public String condiList() {
		log.debug("cardNo="+paperCC.getCard_no());
		List<Epiboly> list = epibolyService.getCondiList(paperCC);
		result = ResultObject.build("0", list);
		return SUCCESS;
	}
	
	/**
	 * 查询所有外包商列表
	 * @return	外包商列表
	 */
	public String listAll() {
		List<Epiboly> list = epibolyService.getAllList();
		result = ResultObject.build("0", list);
		return SUCCESS;
	}

	/**
	 * 添加外包商
	 */
	public String add() {
		log.debug("ftp="+epiboly.getFtp()+",ftpPass="+epiboly.getFtppass()+",ftpPath="+epiboly.getFtppath()+",ftpUser="+epiboly.getFtpuser()
				+",id="+epiboly.getId()+",linkAddr="+epiboly.getLinkaddr()+",linkMan="+epiboly.getLinkman()+",linkPhone="+epiboly.getLinkphone()
				+",name="+epiboly.getName()+",port="+epiboly.getPort()+",remark="+epiboly.getRemark()+",state="+epiboly.getState());
		int type = epibolyService.add(epiboly);
		if(type == 0){
			result = ResultObject.build(String.valueOf(type), "添加成功！");
		} else {
			result = ResultObject.build(String.valueOf(type), "操作失败！");
		}
		return SUCCESS;
	}

	/**
	 * 删除外包商
	 */
	public String del() {
		log.debug("id="+epiboly.getId());
		int type = epibolyService.del(epiboly);
		if(type == 0){
			result = ResultObject.build(String.valueOf(type), "删除成功！");
		} else {
			result = ResultObject.build(String.valueOf(type), "操作失败！");
		}
		return SUCCESS;
	}
	
	/**
	 * 更新外包商
	 */
	public String upd() {
		log.debug("ftp="+epiboly.getFtp()+",ftpPass="+epiboly.getFtppass()+",ftpPath="+epiboly.getFtppath()+",ftpUser="+epiboly.getFtpuser()
				+",id="+epiboly.getId()+",linkAddr="+epiboly.getLinkaddr()+",linkMan="+epiboly.getLinkman()+",linkPhone="+epiboly.getLinkphone()
				+",name="+epiboly.getName()+",port="+epiboly.getPort()+",remark="+epiboly.getRemark()+",state="+epiboly.getState());
		int type = epibolyService.upd(epiboly);
		if(type == 0){
			result = ResultObject.build(String.valueOf(type), "修改成功！");
		} else {
			result = ResultObject.build(String.valueOf(type), "操作失败！");
		}
		return SUCCESS;
	}

	public Epiboly getEpiboly() {
		return epiboly;
	}

	public void setEpiboly(Epiboly epiboly) {
		this.epiboly = epiboly;
	}

	public PaperCityCrd getPaperCC() {
		return paperCC;
	}

	public void setPaperCC(PaperCityCrd paperCC) {
		this.paperCC = paperCC;
	}
	
	public void setStart(int start) {
		this.start = start;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}
	
}
